package com.github.dice.exception;

import com.github.dice.constant.ErrorEnums;
import org.springframework.util.ObjectUtils;

import java.text.MessageFormat;

public class BusinessException extends RuntimeException {

    private static final long serialVersionUID = 2332608236621015980L;

    private String code;

    public BusinessException() {
        super();
    }

    public BusinessException(String message) {
        super(message);
    }

    public BusinessException(String code, String message) {
        super(message);
        this.code = code;
    }

    public BusinessException(ErrorEnums errorEnums) {
        super(errorEnums.getMsg());
        this.code = errorEnums.getCode();
    }

    public BusinessException(ErrorEnums errorEnums, Object... args) {
        super(MessageFormat.format(errorEnums.getMsg(), args));
        this.code = errorEnums.getCode();
    }

    public BusinessException(Throwable cause) {
        super(cause);
    }

    public BusinessException(String message, Throwable cause) {
        super(message, cause);
    }

    public BusinessException(String code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
    }

    public String getCode() {
        return code;
    }
}
